#include "Message.hpp"

// int main()
// {
    // rcp请求测试
    // xu::RpcRequest::Ptr req1 = xu::MessageFactory::create<xu::RpcRequest>();
    //  req1->SetMethod("Add");
    //  Json::Value val1;
    //  val1["num1"] = 1;
    //  val1["num2"] = 2;
    //  req1->SetParams(val1);
    //  std::string body = req1->Serialization();

    // std::cout<<body<<std::endl;

    // xu::RpcRequest::Ptr req2 = xu::MessageFactory::create<xu::RpcRequest>();
    // if(!req2->Deserialization(body))
    // {
    //     std::cout<<"err..."<<std::endl;
    // }

    // req2->check();
    // std::cout<<req2->Method()<<" : "<<req2->Params()["num1"].asInt() <<" - "<< req2->Params()["num2"].asInt()<<std::endl;

    // 请求主题测试
    //     xu::TopicRequest::Ptr req1 = xu::MessageFactory::create<xu::TopicRequest>();
    //     req1->SetKey("news");
    //    // req1->SetOptype(xu::TopicOptype::TOPIC_PUBLISH);
    //     //req1->SetMsg("xuzhengyou");
    //     req1->SetOptype(xu::TopicOptype::TOPIC_CREATE);

    //     std::string body = req1->Serialization();

    //     std::cout<<body<<std::endl;

    //     xu::TopicRequest::Ptr req2 = xu::MessageFactory::create<xu::TopicRequest>();
    //     if(!req2->Deserialization(body))
    //     {
    //         std::cout<<"err..."<<std::endl;
    //     }
    //     req2->check();
    //     //std::cout<<req2->key()<<" : "<<(int)req2->Optype() <<" : "<< req2->Msg()<<std::endl;
    //     std::cout<<req2->key()<<" : "<<(int)req2->Optype() <<" : "<<std::endl;

    // 请求注册等测试
        // xu::ServiceRequest::Ptr req1 = xu::MessageFactory::create<xu::ServiceRequest>();
        // req1->SetMethod("Add");
        // req1->SetOptype(xu::ServiceOptype::SERVICE_REGISTRY);
        // xu::Address addr;
        // addr.first = "127.0.0.1";
        // addr.second = 8080;
        // req1->SetHost(addr);

        // std::string body = req1->Serialization();

        // std::cout<<body<<std::endl;

        // xu::ServiceRequest::Ptr req2 = xu::MessageFactory::create<xu::ServiceRequest>();
        // if(!req2->Deserialization(body))
        // {
        //     std::cout<<"err..."<<std::endl;
        // }

        // req2->check();

        // std::cout<<req2->Method()<<" : "<<(int)req2->Optype() <<" : "<< req2->Host().first<<" : "<<req2->Host().second<<std::endl;
       // std::cout<<req2->Method()<<" : "<<(int)req2->Optype() <<" : "<<std::endl;

    // 响应Rpc测试
    //  xu::RpcResponse::Ptr rsp1 = xu::MessageFactory::create<xu::RpcResponse>();
    //  rsp1->SetRcode(xu::RCode::RCODE_OK);
    //  rsp1->SetResult("aaaa");
    //  std::string body = rsp1->Serialization();

    // std::cout << body << std::endl;

    // xu::RpcResponse::Ptr rsp2 = xu::MessageFactory::create<xu::RpcResponse>();
    // if (!rsp2->Deserialization(body))
    // {
    //     std::cout << "err..." << std::endl;
    // }

    // rsp2->check();

    // std::cout<<(int)rsp2->Rcode()<<" : " <<rsp2->Result()<<std::endl;

    // xu::TopicResponse::Ptr rsp1 = xu::MessageFactory::create<xu::TopicResponse>();
    // rsp1->SetRcode(xu::RCode::RCODE_OK);

    // std::string body = rsp1->Serialization();

    // std::cout << body << std::endl;

    // xu::TopicResponse::Ptr rsp2 = xu::MessageFactory::create<xu::TopicResponse>();
    // if (!rsp2->Deserialization(body))
    // {
    //     std::cout << "err..." << std::endl;
    // }

    // rsp2->check();

    // std::cout << (int)rsp2->Rcode() << std::endl;

//     xu::ServiceResponse::Ptr rsp1 = xu::MessageFactory::create<xu::ServiceResponse>();
//     rsp1->SetRcode(xu::RCode::RCODE_INTERNAL_ERROR);
//     rsp1->SetMethod("news");
//     rsp1->SetOptype(xu::ServiceOptype::SERVICE_DISCOVERY);
//     std::vector<xu::Address> val;
//     val.push_back({"127.0.0.1",2020});
//     val.push_back({"127.0.0.2",2020});

//     rsp1->SetHost(val);
//     std::string body = rsp1->Serialization();

//     std::cout << body << std::endl;

//     xu::ServiceResponse::Ptr rsp2 = xu::MessageFactory::create<xu::ServiceResponse>();
   
//     if (!rsp2->Deserialization(body))
//     {
//         std::cout << "err..." << std::endl;
//     }
//     rsp2->check();
//     std::cout<<(int)rsp2->Rcode()<<" - "<< rsp2->Method()<<" - "<<(int)rsp2->Optype()<<std::endl;

//     std::vector<xu::Address> ret = rsp2->Host();
//     for(auto &e : ret)
//     {
//         std::cout<<e.first<<": "<<e.second<<std::endl;
//     }

//     return 0;
// }